CentOS 6
Sponsored Link

HAProxy : Load Balancing with Layer4 Mode
2015/01/22
 
Configure HAProxy with Layer4 Mode.
This example based on the environment like follows.
       |
-------+-----------------------------------------------
       |
       +-------------------+--------------------+
       |10.0.0.30          |10.0.0.31           |10.0.0.32
 +-----+-----+     +-------+------+     +-------+------+
 | Frontend  |     |   Backend#1  |     |   Backend#2  |
 |  HAProxy  |     | MySQL Server |     | MySQL Server |
 +-----------+     +--------------+     +--------------+

[1] Configure HAProxy.
[root@dlp ~]#
vi /etc/haproxy/haproxy.cfg
global
    log         127.0.0.1 local2 info
    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     256
    maxsslconn  256
    user        haproxy
    group       haproxy
    daemon

defaults
      # set "mode tcp" for Layer4

    mode               tcp
    log                global
    timeout connect    10s
    timeout client     30s
    timeout server     30s

# define frontend and backend servers

frontend  mysql-in
    bind *:3306
    default_backend    backend_servers

backend backend_servers
    balance            roundrobin
    server             db01 10.0.0.31:3306 check
    server             db02 10.0.0.32:3306 check

[root@dlp ~]#
/etc/rc.d/init.d/haproxy restart

Stopping haproxy: [ OK ]
Starting haproxy: [ OK ]
[2] Make sure all works fine to access to the frontend server from a Client with SQL like follows.
[root@desktop ~]#
mysql -u keystone -p -h 10.0.0.30 keystone -e "select * from table01;"

Enter password:
+------+-------------------+
| id   | name              |
+------+-------------------+
|    1 | db01.srv.world |
+------+-------------------+

[root@desktop ~]#
mysql -u keystone -p -h 10.0.0.30 keystone -e "select * from table01;"

Enter password:
+------+-------------------+
| id   | name              |
+------+-------------------+
|    1 | db02.srv.world |
+------+-------------------+
 
Tweet